package com.pi.shisan.component.util;

import java.util.concurrent.CountDownLatch;

public abstract class AnimationThread extends Thread{

    protected volatile boolean destroy;

    private CountDownLatch count = new CountDownLatch(1);


    public void setDestroy() {
        destroy = true;
        this.interrupt();
    }

    @Override
    public final void run() {
        try {
            doRun();
        } finally {
            count.countDown();
        }
    }

    protected abstract void doRun();

    public void awaitDestroy() {
        while (count.getCount() > 0) {
            try {
                count.await();
            } catch (InterruptedException e) {
            }
        }
    }

}
